/**
* 系统管理 日志审计
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>日志审计</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="">
        <el-input size="small" v-model="formInline.var_name" placeholder="输入变量名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
              element-loading-text="拼命加载中" style="width: 100%;">
      <!--      <el-table-column align="center" type="selection" width="60">-->
      <!--      </el-table-column>-->
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column sortable prop="tag_name" label="栏目名称" width="208">
      </el-table-column>
      <el-table-column sortable prop="log_info" label="操作信息" width="680">
      </el-table-column>
      <el-table-column sortable prop="user_name" label="用户名" width="120">
      </el-table-column>
      <el-table-column sortable prop="handle_time" label="操作时间" width="200">
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
import {
  logsList,
  logsListPage,
  logsSearch
} from '../../api/devMG'
import Pagination from '../../components/Pagination'

export default {
  data() {
    return {
      formInline: {
        page: 1,
        limit: 10,
        var_name: '',
        tag_name: '',
        log_info: '',
        user_name: '',
        handle_time: '',
        token: localStorage.getItem('logintoken')
      },
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      listData: [],
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */
  computed: {
    selectParams() { // 当下面的属性变化时，本计算属性会重新计算，得到一个params对象，用于后续传递给axios
      return {
        var_name__icontains: this.formInline.var_name || '',
      };
    },
  },

  watch: {
    selectParams() { // 监听计算属性，当计算属性发生变化向后端发送请求
      logsSearch(this.selectParams).then(res => {
        this.listData = res.data.results
        this.listLoading = false
      })
    }
  },

  /**
   * 创建完毕
   */

  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */

  methods: {
    // 获取数据方法
    getdata(parameter) {
      this.loading = true
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      logsList(parameter)
        .then(res => {
          this.loading = false
          if (res.success == false) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.listData = res.data.results
            // 分页赋值
            this.pageparm.currentPage = this.formInline.page
            this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.data.count
            logsListPage(this.pageparm).then(res => {
              this.listData = res.data.results
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>

